package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("example of time/date usage")
	DateExample()
}

func SleepExample() {
	du, e := time.ParseDuration("4s")
	if e == nil {
		fmt.Println("sleep 4s")
		time.Sleep(du)
	}
	fmt.Println("sleep end...")
}
func DateExample() {
	tm := time.Date(2015, time.June, 22, 15, 05, 05, 0, time.UTC)
	fmt.Printf("time : %T\n", tm)
	fmt.Println(tm)
	tm = time.Now()
	fmt.Println("current time: ", time.Now())
	fmt.Println("--->", tm)
	fmt.Println("year--->", tm.Year())
	fmt.Println("month--->", tm.Month())
	fmt.Println("day--->", tm.Day())
	fmt.Println("hour--->", tm.Hour())
	fmt.Println("minute--->", tm.Minute())
	fmt.Println("second--->", tm.Second())
	fmt.Println("nanosecond--->", tm.Nanosecond)
	fmt.Println("local--->", tm.Local())
	fmt.Println("location--->", tm.Location())
	fmt.Println("zone--->", tm)
}
func ParseDateExample() {
	var s string = "May 12, 2015 at 3:32pm (MST)"
	const longForm = "Jan 2, 2006 at 3:04pm (MST)"
	tm, e := time.Parse(longForm, s)
	if e != nil {
		fmt.Println("parse time: ", tm)
	}

	const shortForm = "2006-Jan-02"
	t, _ := time.Parse(shortForm, "2013-Feb-03")
	fmt.Println(t)

}
